package com.wx.spider.sql.controller;

import com.wx.spider.common.model.CommonResponse;
import com.wx.spider.common.pojo.db.User;
import com.wx.spider.sql.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author:feng
 * @create:2021-04-19 10:41
 */
@RestController
public class TestController {

    @Autowired
    private UserService userService;

    @GetMapping("/getUser")
    public CommonResponse<List<User>> getUser(){
        try {
            CommonResponse<List<User>> result = new CommonResponse<>();
            result.setCode("0000");
            result.setMsg("success");
            result.setData(userService.getALlUser());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResponse.INTERNAL_ERROR_RESPONSE;
        }
    }

    @GetMapping("/getUser2")
    public CommonResponse<List<User>> getUser2(){
        try {
            CommonResponse<List<User>> result = new CommonResponse<>();
            result.setCode("0000");
            result.setMsg("success");
            result.setData(userService.getALlUser2());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResponse.INTERNAL_ERROR_RESPONSE;
        }
    }

    @GetMapping("/getUser3")
    public CommonResponse<List<User>> getUser3(){
        try {
            CommonResponse<List<User>> result = new CommonResponse<>();
            result.setCode("0000");
            result.setMsg("success");
            List<User> list = userService.getALlUser();
            list.addAll(userService.getALlUser2());
            result.setData(list);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResponse.INTERNAL_ERROR_RESPONSE;
        }
    }
}
